<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background: #000;
            text-align: center
        }

        #c1 {
            background: #fff;
        }
    </style>

</head>

<body >
    <canvas id="c1" width="800" height="600">

    </canvas>
</body>
<script>
    //*****不能跨域
    let oC = document.getElementById('c1');
    let gd = oC.getContext('2d');       //图形上下文-绘图用的接口
    let img = new Image();
    img.src='1.jpg';
    img.onload=function(){
        gd.drawImage(img,0,0)
        //获取像素区域
        let imageData=gd.getImageData(0,0,oC.width,oC.height);
         //获取第1行第0列的像素值  r:行   c:列
        alert(
            `
            r:${imageData.data[(1*800+0)*4]}\n
            g:${imageData.data[(1*800+0)*4+1]}\n
            b:${imageData.data[(1*800+0)*4+2]}\n
            a:${imageData.data[(1*800+0)*4+3]}\n
            `
        )
    }




</script>

</html>